home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Base / Debug.cp < prev    next >
Encoding:
Text File  |  1996-02-19  |  4.7 KB  |  164 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Debug.c
  3.  
  4.     Contains:    support for the debug macros and for write line window
  5.  
  6.     Written by:    Bruce Horn, Steve Capps, Larry Kenyon, John Meier, scott douglass, Darin Adler,
  7.                 Paul Mercer, Bryan Stearns, Dave Owens
  8.  
  9.                 Andy Nicholas
  10.  
  11.     Copyright:    © 1988-1995 by Apple Computer, Inc., all rights reserved.
  12.  
  13.          <2>     2/24/95    ga        
  14. */
  15.  
  16. #ifdef MWTRACEBACKTABLES
  17. #pragma traceback on
  18. #endif
  19.  
  20. #include "Debug.h"
  21.  
  22. #ifndef DEBUG
  23.  
  24. #ifdef DEBUGEXPORTED
  25.  
  26.  
  27. void dbgAssertPrint(const char* fmt, ...)
  28.     {
  29.     }
  30.  
  31. void dbgAssert(const char* filename, SInt32 line)
  32.     {
  33.     }
  34.  
  35. void dbgGuard(const char* filename, SInt32 line)
  36.     {
  37.     }
  38.  
  39. void dbgInvalidPointer(const void* pointer, const char* filename, SInt32 line)
  40.     {
  41.     }
  42.     
  43. void dbgInvalidHandle(const void** handle, const char* filename, SInt32 line)
  44.     {
  45.     }
  46.  
  47. #endif // DEBUGEXPORTED
  48.  
  49. #else // DEBUG
  50.  
  51. //#include <stdio.h>
  52. //#include <stdarg.h>
  53. //#include <string.h>
  54. // #include <iostream.h>
  55.  
  56. //
  57. // For DebugStr and nil
  58. //
  59. #include <Types.h>
  60.  
  61. //
  62. // For c2pstr
  63. //
  64. #include <Strings.h>
  65.  
  66.  
  67. //#ifndef POWERPC
  68. //#include <NubDispatch.h>
  69. //#endif
  70.  
  71.  
  72. #pragma segment Debug
  73.  
  74. const char kNewLine = 0x0D;
  75.  
  76. //----------------------------------------------------------------------------------------
  77. // dbgAssertPrint: 
  78. //----------------------------------------------------------------------------------------
  79. void dbgAssertPrint(const char* /*fmt*/, ...)
  80.     {
  81. #if 0
  82.     char msg[256];
  83.     va_list ap;
  84.     va_start(ap, fmt);
  85.     vsprintf(msg, fmt, ap);
  86.     va_end(ap);
  87.  
  88. #if 0
  89.     //
  90.     // The cool thing to do would be to use iostream to send
  91.     // debugging information to 'cerr', and have another module
  92.     // elsewhere that redirected cerr to somewhere else (e.g.
  93.     // a debug window, DebugStr, etc.).
  94.     //
  95.     cerr << msg;
  96. #else
  97.     c2pstr(msg);
  98.  
  99. #ifdef SIXTYEIGHTK
  100.     if (NubIsInstalled() && NubStartDebuggingMe())
  101.         {
  102.         msg[++msg[0]] = kNewLine;        // Add a return character
  103.         SysBreakStr((ConstStr255Param)msg);    // ••• change this to SysBreakFunc if you don't want to stop execution
  104.         }
  105.     else
  106. #endif
  107.         DebugStr((ConstStr255Param)msg);
  108. #endif
  109. #endif
  110.     } // dbgAssertPrint 
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // dbgAssert: 
  114. //----------------------------------------------------------------------------------------
  115. void dbgAssert(const char* filename, SInt32 line)
  116.     {
  117.     dbgAssertPrint("Assertion failed # %s: %ld", filename, line);
  118.     } // dbgAssert 
  119.  
  120. //----------------------------------------------------------------------------------------
  121. // dbgGuard: 
  122. //----------------------------------------------------------------------------------------
  123. void dbgGuard(const char* filename, SInt32 line)
  124.     {
  125.     dbgAssertPrint("Guard failed # %s: %ld", filename, line);
  126.     } // dbgGuard 
  127.  
  128. //----------------------------------------------------------------------------------------
  129. // dbgInvalidPointer: 
  130. //----------------------------------------------------------------------------------------
  131. void dbgInvalidPointer(const void* pointer, const char* filename, SInt32 line)
  132.     {
  133.     if(pointer == nil)
  134.         dbgAssertPrint("FATAL ERROR: Nil pointer # %s: %ld", filename, line);
  135.     else if((((UInt32)pointer) & 0x01) != 0)
  136.         dbgAssertPrint("FATAL ERROR: Odd pointer (%x) # %s: %ld", (UInt32)pointer, filename, line);
  137.     else if((*((UInt32*)pointer) == 0xDEADBEEF) || (*((UInt32*)pointer) == 0xBEEFDEAD))
  138.         dbgAssertPrint("FATAL ERROR: Pointer to DEADBEEF (%x->%x) # %s: %ld", (UInt32)pointer, *((UInt32*)pointer), filename, line);
  139.     } // dbgInvalidPointer 
  140.  
  141. //----------------------------------------------------------------------------------------
  142. // dbgInvalidHandle: 
  143. //
  144. // I considered trying to use common code in dbgInvalidPointer and dbgInvalidHandle,
  145. // but different output is required for invalid handles (esp wrt invalid master
  146. // pointers), so I didn't think it was worth the effort.
  147. //----------------------------------------------------------------------------------------
  148. void dbgInvalidHandle(const void** handle, const char* filename, SInt32 line)
  149.     {
  150.     if(handle == nil)
  151.         dbgAssertPrint("FATAL ERROR: Nil handle # %s: %ld", filename, line);
  152.     else if((((UInt32)handle) & 0x01) != 0)
  153.         dbgAssertPrint("FATAL ERROR: Odd handle (%x) # %s: %ld", (UInt32)handle, filename, line);
  154.     else if(*handle == nil)
  155.         dbgAssertPrint("FATAL ERROR: Purged handle (%x->nil) # %s: %ld", (UInt32)handle, filename, line);
  156.     else if(((*((UInt32*)handle)) & 0x01) != 0)
  157.         dbgAssertPrint("FATAL ERROR: Corrupt handle (%x->%x) # %s: %ld", (UInt32)handle, *((UInt32*)handle), filename, line);
  158.     else if((*((UInt32*)(*handle)) == 0xDEADBEEF) || (*((UInt32*)(*handle)) == 0xBEEFDEAD))
  159.         dbgAssertPrint("FATAL ERROR: Handle to DEADBEEF (%x->%x->%x) # %s: %ld", (UInt32)handle, *((UInt32*)handle), **((UInt32**)handle), filename, line);
  160.     } // dbgInvalidHandle 
  161.  
  162. #endif // DEBUG
  163.  
  164.